
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>4-9 CDN 加速 · 深入浅出 Webpack</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="吴浩麟">
        <meta name="identifier" content="9787121331725" scheme="ISBN">
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-modal/index.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        

    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="4-10使用TreeShaking.html" />
    
    
    <link rel="prev" href="4-8压缩代码.html" />
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"buttons":[{"user":"gwuhaolin","type":"follow","size":"small","width":"150"},{"user":"gwuhaolin","repo":"dive-into-webpack","type":"star","size":"small"}]};
    </script>


    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
  
  

  

  
  
  

<li class="chapter " data-level="1.1" data-path="../">
  
  <a href="../">
    
                    
                    深入浅出 Webpack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.2" data-path="../前言.html">
  
  <a href="../前言.html">
    
                    
                    前言
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3" data-path="../1入门/">
  
  <a href="../1入门/">
    
                    
                    第1章 入门
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.3.1" data-path="../1入门/1-1前端的发展.html">
  
  <a href="../1入门/1-1前端的发展.html">
    
                    
                    1-1 前端的发展
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.2" data-path="../1入门/1-2常见的构建工具及对比.html">
  
  <a href="../1入门/1-2常见的构建工具及对比.html">
    
                    
                    1-2 常见的构建工具及对比
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.3" data-path="../1入门/1-3安装与使用.html">
  
  <a href="../1入门/1-3安装与使用.html">
    
                    
                    1-3 安装与使用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.4" data-path="../1入门/1-4使用Loader.html">
  
  <a href="../1入门/1-4使用Loader.html">
    
                    
                    1-4 使用 Loader
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.5" data-path="../1入门/1-5使用Plugin.html">
  
  <a href="../1入门/1-5使用Plugin.html">
    
                    
                    1-5 使用 Plugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.6" data-path="../1入门/1-6使用DevServer.html">
  
  <a href="../1入门/1-6使用DevServer.html">
    
                    
                    1-6 使用 DevServer
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.7" data-path="../1入门/1-7核心概念.html">
  
  <a href="../1入门/1-7核心概念.html">
    
                    
                    1-7 核心概念
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.4" data-path="../2配置/">
  
  <a href="../2配置/">
    
                    
                    第2章 配置
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.4.1" data-path="../2配置/2-1Entry.html">
  
  <a href="../2配置/2-1Entry.html">
    
                    
                    2-1 Entry
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.2" data-path="../2配置/2-2Output.html">
  
  <a href="../2配置/2-2Output.html">
    
                    
                    2-2 Output
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.3" data-path="../2配置/2-3Module.html">
  
  <a href="../2配置/2-3Module.html">
    
                    
                    2-3 Module
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.4" data-path="../2配置/2-4Resolve.html">
  
  <a href="../2配置/2-4Resolve.html">
    
                    
                    2-4 Resolve
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.5" data-path="../2配置/2-5Plugins.html">
  
  <a href="../2配置/2-5Plugins.html">
    
                    
                    2-5 Plugins
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.6" data-path="../2配置/2-6DevServer.html">
  
  <a href="../2配置/2-6DevServer.html">
    
                    
                    2-6 DevServer
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.7" data-path="../2配置/2-7其它配置项.html">
  
  <a href="../2配置/2-7其它配置项.html">
    
                    
                    2-7 其它配置项
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.8" data-path="../2配置/2-8整体配置结构.html">
  
  <a href="../2配置/2-8整体配置结构.html">
    
                    
                    2-8 整体配置结构
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.9" data-path="../2配置/2-9多种配置类型.html">
  
  <a href="../2配置/2-9多种配置类型.html">
    
                    
                    2-9 多种配置类型
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.10" data-path="../2配置/2-10配置总结.html">
  
  <a href="../2配置/2-10配置总结.html">
    
                    
                    2-10 配置总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.5" data-path="../3实战/">
  
  <a href="../3实战/">
    
                    
                    第3章 实战
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.5.1" data-path="../3实战/3-1使用ES6语言.html">
  
  <a href="../3实战/3-1使用ES6语言.html">
    
                    
                    3-1 使用 ES6 语言
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.2" data-path="../3实战/3-2使用TypeScript语言.html">
  
  <a href="../3实战/3-2使用TypeScript语言.html">
    
                    
                    3-2 使用 TypeScript 语言
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.3" data-path="../3实战/3-3使用Flow检查器.html">
  
  <a href="../3实战/3-3使用Flow检查器.html">
    
                    
                    3-3 使用 Flow 检查器
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.4" data-path="../3实战/3-4使用SCSS语言.html">
  
  <a href="../3实战/3-4使用SCSS语言.html">
    
                    
                    3-4 使用 SCSS
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.5" data-path="../3实战/3-5使用PostCSS.html">
  
  <a href="../3实战/3-5使用PostCSS.html">
    
                    
                    3-5 使用 PostCSS
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.6" data-path="../3实战/3-6使用React框架.html">
  
  <a href="../3实战/3-6使用React框架.html">
    
                    
                    3-6 使用 React 框架
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.7" data-path="../3实战/3-7使用Vue框架.html">
  
  <a href="../3实战/3-7使用Vue框架.html">
    
                    
                    3-7 使用 Vue 框架
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.8" data-path="../3实战/3-8使用Angular2框架.html">
  
  <a href="../3实战/3-8使用Angular2框架.html">
    
                    
                    3-8 使用 Angular2 框架
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.9" data-path="../3实战/3-9为单页应用生成HTML.html">
  
  <a href="../3实战/3-9为单页应用生成HTML.html">
    
                    
                    3-9 为单页应用生成 HTML
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.10" data-path="../3实战/3-10管理多个单页应用.html">
  
  <a href="../3实战/3-10管理多个单页应用.html">
    
                    
                    3-10 管理多个单页应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.11" data-path="../3实战/3-11构建同构应用.html">
  
  <a href="../3实战/3-11构建同构应用.html">
    
                    
                    3-11 构建同构应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.12" data-path="../3实战/3-12构建Electron应用.html">
  
  <a href="../3实战/3-12构建Electron应用.html">
    
                    
                    3-12 构建 Electron 应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.13" data-path="../3实战/3-13构建Npm模块.html">
  
  <a href="../3实战/3-13构建Npm模块.html">
    
                    
                    3-13 构建 Npm 模块
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.14" data-path="../3实战/3-14构建离线应用.html">
  
  <a href="../3实战/3-14构建离线应用.html">
    
                    
                    3-14 构建离线应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.15" data-path="../3实战/3-15搭配NpmScript.html">
  
  <a href="../3实战/3-15搭配NpmScript.html">
    
                    
                    3-15 搭配 Npm Script
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.16" data-path="../3实战/3-16检查代码.html">
  
  <a href="../3实战/3-16检查代码.html">
    
                    
                    3-16 检查代码
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.17" data-path="../3实战/3-17通过Node.jsAPI启动Webpack.html">
  
  <a href="../3实战/3-17通过Node.jsAPI启动Webpack.html">
    
                    
                    3-17 通过 Node.js API 启动 Webpack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.18" data-path="../3实战/3-18使用WebpackDevMiddleware.html">
  
  <a href="../3实战/3-18使用WebpackDevMiddleware.html">
    
                    
                    3-18 使用 Webpack Dev Middleware
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.19" data-path="../3实战/3-19加载图片.html">
  
  <a href="../3实战/3-19加载图片.html">
    
                    
                    3-19 加载图片
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.20" data-path="../3实战/3-20加载SVG.html">
  
  <a href="../3实战/3-20加载SVG.html">
    
                    
                    3-20 加载SVG
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.21" data-path="../3实战/3-21加载SourceMap.html">
  
  <a href="../3实战/3-21加载SourceMap.html">
    
                    
                    3-21 加载 Source Map
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.22" data-path="../3实战/3-22实战总结.html">
  
  <a href="../3实战/3-22实战总结.html">
    
                    
                    3-22 实战总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.6" data-path="./">
  
  <a href="./">
    
                    
                    第4章 优化
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.6.1" data-path="4-1缩小文件搜索范围.html">
  
  <a href="4-1缩小文件搜索范围.html">
    
                    
                    4-1 缩小文件搜索范围
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.2" data-path="4-2使用DllPlugin.html">
  
  <a href="4-2使用DllPlugin.html">
    
                    
                    4-2 使用 DllPlugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.3" data-path="4-3使用HappyPack.html">
  
  <a href="4-3使用HappyPack.html">
    
                    
                    4-3 使用 HappyPack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.4" data-path="4-4使用ParallelUglifyPlugin.html">
  
  <a href="4-4使用ParallelUglifyPlugin.html">
    
                    
                    4-4 使用 ParallelUglifyPlugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.5" data-path="4-5使用自动刷新.html">
  
  <a href="4-5使用自动刷新.html">
    
                    
                    4-5 使用自动刷新
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.6" data-path="4-6开启模块热替换.html">
  
  <a href="4-6开启模块热替换.html">
    
                    
                    4-6 开启模块热替换
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.7" data-path="4-7区分环境.html">
  
  <a href="4-7区分环境.html">
    
                    
                    4-7 区分环境
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.8" data-path="4-8压缩代码.html">
  
  <a href="4-8压缩代码.html">
    
                    
                    4-8 压缩代码
            
    </a>
    

    
</li>

<li class="chapter active" data-level="1.6.9" data-path="4-9CDN加速.html">
  
  <a href="4-9CDN加速.html">
    
                    
                    4-9 CDN 加速
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.10" data-path="4-10使用TreeShaking.html">
  
  <a href="4-10使用TreeShaking.html">
    
                    
                    4-10 使用 Tree Shaking
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.11" data-path="4-11提取公共代码.html">
  
  <a href="4-11提取公共代码.html">
    
                    
                    4-11 提取公共代码
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.12" data-path="4-12按需加载.html">
  
  <a href="4-12按需加载.html">
    
                    
                    4-12 按需加载
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.13" data-path="4-13使用Prepack.html">
  
  <a href="4-13使用Prepack.html">
    
                    
                    4-13 使用 Prepack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.14" data-path="4-14开启ScopeHoisting.html">
  
  <a href="4-14开启ScopeHoisting.html">
    
                    
                    4-14 开启 Scope Hoisting
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.15" data-path="4-15输出分析.html">
  
  <a href="4-15输出分析.html">
    
                    
                    4-15 输出分析
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.16" data-path="4-16优化总结.html">
  
  <a href="4-16优化总结.html">
    
                    
                    4-16 优化总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.7" data-path="../5原理/">
  
  <a href="../5原理/">
    
                    
                    第5章 原理
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.7.1" data-path="../5原理/5-1工作原理概括.html">
  
  <a href="../5原理/5-1工作原理概括.html">
    
                    
                    5-1 工作原理概括
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.2" data-path="../5原理/5-2输出文件分析.html">
  
  <a href="../5原理/5-2输出文件分析.html">
    
                    
                    5-2 输出文件分析
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.3" data-path="../5原理/5-3编写Loader.html">
  
  <a href="../5原理/5-3编写Loader.html">
    
                    
                    5-3 编写 Loader
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.4" data-path="../5原理/5-4编写Plugin.html">
  
  <a href="../5原理/5-4编写Plugin.html">
    
                    
                    5-4 编写 Plugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.5" data-path="../5原理/5-5调试Webpack.html">
  
  <a href="../5原理/5-5调试Webpack.html">
    
                    
                    5-5 调试 Webpack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.6" data-path="../5原理/5-6原理总结.html">
  
  <a href="../5原理/5-6原理总结.html">
    
                    
                    5-6 原理总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.8" >
  
      <span>
            
                    
                    附录
            
    </span>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.8.1" data-path="../附录/常用Loaders.html">
  
  <a href="../附录/常用Loaders.html">
    
                    
                    常用 Loaders
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.8.2" data-path="../附录/常用Plugins.html">
  
  <a href="../附录/常用Plugins.html">
    
                    
                    常用 Plugins
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.8.3" data-path="../附录/其它Webpack学习资源.html">
  
  <a href="../附录/其它Webpack学习资源.html">
    
                    
                    其它 Webpack 学习资源
            
    </a>
    

    
</li>


    </ul>
    
</li>


  

  <li class="divider"></li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >4-9 CDN 加速</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="4-9-cdn-&#x52A0;&#x901F;">4-9 CDN &#x52A0;&#x901F;</h1>
<h2 id="&#x4EC0;&#x4E48;&#x662F;-cdn">&#x4EC0;&#x4E48;&#x662F; CDN</h2>
<p>&#x867D;&#x7136;&#x524D;&#x9762;&#x901A;&#x8FC7;&#x4E86;&#x538B;&#x7F29;&#x4EE3;&#x7801;&#x7684;&#x624B;&#x6BB5;&#x6765;&#x51CF;&#x5C0F;&#x7F51;&#x7EDC;&#x4F20;&#x8F93;&#x5927;&#x5C0F;&#xFF0C;&#x4F46;&#x5B9E;&#x9645;&#x4E0A;&#x6700;&#x5F71;&#x54CD;&#x7528;&#x6237;&#x4F53;&#x9A8C;&#x7684;&#x8FD8;&#x662F;&#x7F51;&#x9875;&#x9996;&#x6B21;&#x6253;&#x5F00;&#x65F6;&#x7684;&#x52A0;&#x8F7D;&#x7B49;&#x5F85;&#x3002;
&#x5BFC;&#x81F4;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x7684;&#x6839;&#x672C;&#x662F;&#x7F51;&#x7EDC;&#x4F20;&#x8F93;&#x8FC7;&#x7A0B;&#x8017;&#x65F6;&#x5927;&#xFF0C;CDN &#x7684;&#x4F5C;&#x7528;&#x5C31;&#x662F;&#x52A0;&#x901F;&#x7F51;&#x7EDC;&#x4F20;&#x8F93;&#x3002;</p>
<p>CDN &#x53C8;&#x53EB;&#x5185;&#x5BB9;&#x5206;&#x53D1;&#x7F51;&#x7EDC;&#xFF0C;&#x901A;&#x8FC7;&#x628A;&#x8D44;&#x6E90;&#x90E8;&#x7F72;&#x5230;&#x4E16;&#x754C;&#x5404;&#x5730;&#xFF0C;&#x7528;&#x6237;&#x5728;&#x8BBF;&#x95EE;&#x65F6;&#x6309;&#x7167;&#x5C31;&#x8FD1;&#x539F;&#x5219;&#x4ECE;&#x79BB;&#x7528;&#x6237;&#x6700;&#x8FD1;&#x7684;&#x670D;&#x52A1;&#x5668;&#x83B7;&#x53D6;&#x8D44;&#x6E90;&#xFF0C;&#x4ECE;&#x800C;&#x52A0;&#x901F;&#x8D44;&#x6E90;&#x7684;&#x83B7;&#x53D6;&#x901F;&#x5EA6;&#x3002;
CDN &#x5176;&#x5B9E;&#x662F;&#x901A;&#x8FC7;&#x4F18;&#x5316;&#x7269;&#x7406;&#x94FE;&#x8DEF;&#x5C42;&#x4F20;&#x8F93;&#x8FC7;&#x7A0B;&#x4E2D;&#x7684;&#x7F51;&#x901F;&#x6709;&#x9650;&#x3001;&#x4E22;&#x5305;&#x7B49;&#x95EE;&#x9898;&#x6765;&#x63D0;&#x5347;&#x7F51;&#x901F;&#x7684;&#xFF0C;&#x5176;&#x5927;&#x81F4;&#x539F;&#x7406;&#x53EF;&#x4EE5;&#x5982;&#x4E0B;&#xFF1A;</p>
<p><img src="img/4-9cdn-arch.png" alt="&#x56FE;4-9-1 CDN &#x539F;&#x7406;"></p>
<p>&#x5728;&#x672C;&#x8282;&#x4E2D;&#x4F60;&#x4E0D;&#x5FC5;&#x7406;&#x89E3; CDN &#x7684;&#x5177;&#x4F53;&#x8FD0;&#x884C;&#x6D41;&#x7A0B;&#x548C;&#x5B9E;&#x73B0;&#x539F;&#x7406;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x7B80;&#x5355;&#x7684;&#x628A; CDN &#x670D;&#x52A1;&#x770B;&#x4F5C;&#x6210;&#x901F;&#x5EA6;&#x66F4;&#x5FEB;&#x7684; HTTP &#x670D;&#x52A1;&#x3002;
&#x5E76;&#x4E14;&#x76EE;&#x524D;&#x5F88;&#x591A;&#x5927;&#x516C;&#x53F8;&#x90FD;&#x4F1A;&#x5EFA;&#x7ACB;&#x81EA;&#x5DF1;&#x7684; CDN &#x670D;&#x52A1;&#xFF0C;&#x5C31;&#x7B97;&#x4F60;&#x81EA;&#x5DF1;&#x6CA1;&#x6709;&#x8D44;&#x6E90;&#x53BB;&#x642D;&#x5EFA;&#x4E00;&#x5957; CDN &#x670D;&#x52A1;&#xFF0C;&#x5404;&#x5927;&#x4E91;&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x5546;&#x90FD;&#x63D0;&#x4F9B;&#x4E86;&#x6309;&#x91CF;&#x6536;&#x8D39;&#x7684; CDN &#x670D;&#x52A1;&#x3002;</p>
<h2 id="&#x63A5;&#x5165;-cdn">&#x63A5;&#x5165; CDN</h2>
<p>&#x8981;&#x7ED9;&#x7F51;&#x7AD9;&#x63A5;&#x5165; CDN&#xFF0C;&#x9700;&#x8981;&#x628A;&#x7F51;&#x9875;&#x7684;&#x9759;&#x6001;&#x8D44;&#x6E90;&#x4E0A;&#x4F20;&#x5230; CDN &#x670D;&#x52A1;&#x4E0A;&#x53BB;&#xFF0C;&#x5728;&#x670D;&#x52A1;&#x8FD9;&#x4E9B;&#x9759;&#x6001;&#x8D44;&#x6E90;&#x7684;&#x65F6;&#x5019;&#x9700;&#x8981;&#x901A;&#x8FC7; CDN &#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x7684; URL &#x5730;&#x5740;&#x53BB;&#x8BBF;&#x95EE;&#x3002;</p>
<p>&#x4E3E;&#x4E2A;&#x8BE6;&#x7EC6;&#x7684;&#x4F8B;&#x5B50;&#xFF0C;&#x6709;&#x4E00;&#x4E2A;&#x5355;&#x9875;&#x5E94;&#x7528;&#xFF0C;&#x6784;&#x5EFA;&#x51FA;&#x7684;&#x4EE3;&#x7801;&#x7ED3;&#x6784;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code>dist
|-- app_9d89c964.js
|-- app_a6976b6d.css
|-- arch_ae805d49.png
`-- index.html
</code></pre><p>&#x5176;&#x4E2D; <code>index.html</code> &#x5185;&#x5BB9;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">&quot;UTF-8&quot;</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;stylesheet&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;app_a6976b6d.css&quot;</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;app&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;app_9d89c964.js&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p><code>app_a6976b6d.css</code>&#x5185;&#x5BB9;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span>{<span class="hljs-attribute">background</span>:<span class="hljs-built_in">url</span>(arch_ae805d49.png) repeat}<span class="hljs-selector-tag">h1</span>{<span class="hljs-attribute">color</span>:red}
</code></pre>
<p>&#x53EF;&#x4EE5;&#x770B;&#x51FA;&#x5230;&#x5BFC;&#x5165;&#x8D44;&#x6E90;&#x65F6;&#x90FD;&#x662F;&#x901A;&#x8FC7;&#x76F8;&#x5BF9;&#x8DEF;&#x5F84;&#x53BB;&#x8BBF;&#x95EE;&#x7684;&#xFF0C;&#x5F53;&#x628A;&#x8FD9;&#x4E9B;&#x8D44;&#x6E90;&#x90FD;&#x653E;&#x5230;&#x540C;&#x4E00;&#x4E2A; CDN &#x670D;&#x52A1;&#x4E0A;&#x53BB;&#x65F6;&#xFF0C;&#x7F51;&#x9875;&#x662F;&#x80FD;&#x6B63;&#x5E38;&#x4F7F;&#x7528;&#x7684;&#x3002;
&#x4F46;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#x7531;&#x4E8E; CDN &#x670D;&#x52A1;&#x4E00;&#x822C;&#x90FD;&#x4F1A;&#x7ED9;&#x8D44;&#x6E90;&#x5F00;&#x542F;&#x5F88;&#x957F;&#x65F6;&#x95F4;&#x7684;&#x7F13;&#x5B58;&#xFF0C;&#x4F8B;&#x5982;&#x7528;&#x6237;&#x4ECE; CDN &#x4E0A;&#x83B7;&#x53D6;&#x5230;&#x4E86; <code>index.html</code> &#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#x540E;&#xFF0C;
&#x5373;&#x4F7F;&#x4E4B;&#x540E;&#x7684;&#x53D1;&#x5E03;&#x64CD;&#x4F5C;&#x628A; <code>index.html</code> &#x6587;&#x4EF6;&#x7ED9;&#x91CD;&#x65B0;&#x8986;&#x76D6;&#x4E86;&#xFF0C;&#x4F46;&#x662F;&#x7528;&#x6237;&#x5728;&#x5F88;&#x957F;&#x4E00;&#x6BB5;&#x65F6;&#x95F4;&#x5185;&#x8FD8;&#x662F;&#x8FD0;&#x884C;&#x7684;&#x4E4B;&#x524D;&#x7684;&#x7248;&#x672C;&#xFF0C;&#x8FD9;&#x4F1A;&#x65B0;&#x7684;&#x5BFC;&#x81F4;&#x53D1;&#x5E03;&#x4E0D;&#x80FD;&#x7ACB;&#x5373;&#x751F;&#x6548;&#x3002;</p>
<p>&#x8981;&#x907F;&#x514D;&#x4EE5;&#x4E0A;&#x95EE;&#x9898;&#xFF0C;&#x4E1A;&#x754C;&#x6BD4;&#x8F83;&#x6210;&#x719F;&#x7684;&#x505A;&#x6CD5;&#x662F;&#x8FD9;&#x6837;&#x7684;&#xFF1A;</p>
<ul>
<li>&#x9488;&#x5BF9; HTML &#x6587;&#x4EF6;&#xFF1A;&#x4E0D;&#x5F00;&#x542F;&#x7F13;&#x5B58;&#xFF0C;&#x628A; HTML &#x653E;&#x5230;&#x81EA;&#x5DF1;&#x7684;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#xFF0C;&#x800C;&#x4E0D;&#x662F; CDN &#x670D;&#x52A1;&#x4E0A;&#xFF0C;&#x540C;&#x65F6;&#x5173;&#x95ED;&#x81EA;&#x5DF1;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x7684;&#x7F13;&#x5B58;&#x3002;&#x81EA;&#x5DF1;&#x7684;&#x670D;&#x52A1;&#x5668;&#x53EA;&#x63D0;&#x4F9B; HTML &#x6587;&#x4EF6;&#x548C;&#x6570;&#x636E;&#x63A5;&#x53E3;&#x3002;</li>
<li>&#x9488;&#x5BF9;&#x9759;&#x6001;&#x7684; JavaScript&#x3001;CSS&#x3001;&#x56FE;&#x7247;&#x7B49;&#x6587;&#x4EF6;&#xFF1A;&#x5F00;&#x542F; CDN &#x548C;&#x7F13;&#x5B58;&#xFF0C;&#x4E0A;&#x4F20;&#x5230; CDN &#x670D;&#x52A1;&#x4E0A;&#x53BB;&#xFF0C;&#x540C;&#x65F6;&#x7ED9;&#x6BCF;&#x4E2A;&#x6587;&#x4EF6;&#x540D;&#x5E26;&#x4E0A;&#x7531;&#x6587;&#x4EF6;&#x5185;&#x5BB9;&#x7B97;&#x51FA;&#x7684; Hash &#x503C;&#xFF0C; &#x4F8B;&#x5982;&#x4E0A;&#x9762;&#x7684; <code>app_a6976b6d.css</code> &#x6587;&#x4EF6;&#x3002;
&#x5E26;&#x4E0A; Hash &#x503C;&#x7684;&#x539F;&#x56E0;&#x662F;&#x6587;&#x4EF6;&#x540D;&#x4F1A;&#x968F;&#x7740;&#x6587;&#x4EF6;&#x5185;&#x5BB9;&#x800C;&#x53D8;&#x5316;&#xFF0C;&#x53EA;&#x8981;&#x6587;&#x4EF6;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x5176;&#x5BF9;&#x5E94;&#x7684; URL &#x5C31;&#x4F1A;&#x53D8;&#x5316;&#xFF0C;&#x5B83;&#x5C31;&#x4F1A;&#x88AB;&#x91CD;&#x65B0;&#x4E0B;&#x8F7D;&#xFF0C;&#x65E0;&#x8BBA;&#x7F13;&#x5B58;&#x65F6;&#x95F4;&#x6709;&#x591A;&#x957F;&#x3002;</li>
</ul>
<p>&#x91C7;&#x7528;&#x4EE5;&#x4E0A;&#x65B9;&#x6848;&#x540E;&#xFF0C;&#x5728; HTML &#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x8D44;&#x6E90;&#x5F15;&#x5165;&#x5730;&#x5740;&#x4E5F;&#x9700;&#x8981;&#x6362;&#x6210; CDN &#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x7684;&#x5730;&#x5740;&#xFF0C;&#x4F8B;&#x5982;&#x4EE5;&#x4E0A;&#x7684; <code>index.html</code> &#x53D8;&#x4E3A;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">&quot;UTF-8&quot;</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;stylesheet&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;//cdn.com/id/app_a6976b6d.css&quot;</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;app&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;//cdn.com/id/app_9d89c964.js&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>&#x5E76;&#x4E14; <code>app_a6976b6d.css</code> &#x7684;&#x5185;&#x5BB9;&#x4E5F;&#x5E94;&#x8BE5;&#x53D8;&#x4E3A;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span>{<span class="hljs-attribute">background</span>:<span class="hljs-built_in">url</span>(//cdn.com/id/arch_ae805d49.png) repeat}<span class="hljs-selector-tag">h1</span>{<span class="hljs-attribute">color</span>:red}
</code></pre>
<p>&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x4E4B;&#x524D;&#x7684;&#x76F8;&#x5BF9;&#x8DEF;&#x5F84;&#xFF0C;&#x90FD;&#x53D8;&#x6210;&#x4E86;&#x7EDD;&#x5BF9;&#x7684;&#x6307;&#x5411; CDN &#x670D;&#x52A1;&#x7684; URL &#x5730;&#x5740;&#x3002;</p>
<blockquote>
<p>&#x5982;&#x679C;&#x4F60;&#x5BF9;&#x5F62;&#x5982; <code>//cdn.com/id/app_a6976b6d.css</code> &#x8FD9;&#x6837;&#x7684; URL &#x611F;&#x5230;&#x964C;&#x751F;&#xFF0C;&#x4F60;&#x9700;&#x8981;&#x77E5;&#x9053;&#x8FD9;&#x79CD; URL &#x7701;&#x6389;&#x4E86;&#x524D;&#x9762;&#x7684; <code>http:</code> &#x6216;&#x8005; <code>https:</code> &#x524D;&#x7F00;&#xFF0C;
&#x8FD9;&#x6837;&#x505A;&#x7684;&#x597D;&#x5904;&#x65F6;&#x5728;&#x8BBF;&#x95EE;&#x8FD9;&#x4E9B;&#x8D44;&#x6E90;&#x7684;&#x65F6;&#x5019;&#x4F1A;&#x81EA;&#x52A8;&#x7684;&#x6839;&#x636E;&#x5F53;&#x524D; HTML &#x7684; URL &#x662F;&#x91C7;&#x7528;&#x4EC0;&#x4E48;&#x6A21;&#x5F0F;&#x53BB;&#x51B3;&#x5B9A;&#x662F;&#x91C7;&#x7528; HTTP &#x8FD8;&#x662F; HTTPS &#x6A21;&#x5F0F;&#x3002;</p>
</blockquote>
<p>&#x9664;&#x6B64;&#x4E4B;&#x5916;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x8FD8;&#x77E5;&#x9053;&#x6D4F;&#x89C8;&#x5668;&#x6709;&#x4E00;&#x4E2A;&#x89C4;&#x5219;&#x662F;&#x540C;&#x4E00;&#x65F6;&#x523B;&#x9488;&#x5BF9;&#x540C;&#x4E00;&#x4E2A;&#x57DF;&#x540D;&#x7684;&#x8D44;&#x6E90;&#x5E76;&#x884C;&#x8BF7;&#x6C42;&#x662F;&#x6709;&#x9650;&#x5236;&#x7684;&#x8BDD;&#xFF08;&#x5177;&#x4F53;&#x6570;&#x5B57;&#x5927;&#x6982;4&#x4E2A;&#x5DE6;&#x53F3;&#xFF0C;&#x4E0D;&#x540C;&#x6D4F;&#x89C8;&#x5668;&#x53EF;&#x80FD;&#x4E0D;&#x540C;&#xFF09;&#xFF0C;
&#x4F60;&#x4F1A;&#x53D1;&#x73B0;&#x4E0A;&#x9762;&#x7684;&#x505A;&#x6CD5;&#x6709;&#x4E2A;&#x5F88;&#x5927;&#x7684;&#x95EE;&#x9898;&#x3002;&#x7531;&#x4E8E;&#x6240;&#x6709;&#x9759;&#x6001;&#x8D44;&#x6E90;&#x90FD;&#x653E;&#x5230;&#x4E86;&#x540C;&#x4E00;&#x4E2A; CDN &#x670D;&#x52A1;&#x7684;&#x57DF;&#x540D;&#x4E0B;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x4E0A;&#x9762;&#x7684; <code>cdn.com</code>&#x3002;
&#x5982;&#x679C;&#x7F51;&#x9875;&#x7684;&#x8D44;&#x6E90;&#x5F88;&#x591A;&#xFF0C;&#x4F8B;&#x5982;&#x6709;&#x5F88;&#x591A;&#x56FE;&#x7247;&#xFF0C;&#x5C31;&#x4F1A;&#x5BFC;&#x81F4;&#x8D44;&#x6E90;&#x7684;&#x52A0;&#x8F7D;&#x88AB;&#x963B;&#x585E;&#xFF0C;&#x56E0;&#x4E3A;&#x540C;&#x65F6;&#x53EA;&#x80FD;&#x52A0;&#x8F7D;&#x51E0;&#x4E2A;&#xFF0C;&#x5FC5;&#x987B;&#x7B49;&#x5176;&#x5B83;&#x8D44;&#x6E90;&#x52A0;&#x8F7D;&#x5B8C;&#x624D;&#x80FD;&#x7EE7;&#x7EED;&#x52A0;&#x8F7D;&#x3002;
&#x8981;&#x89E3;&#x51B3;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#xFF0C;&#x53EF;&#x4EE5;&#x628A;&#x8FD9;&#x4E9B;&#x9759;&#x6001;&#x8D44;&#x6E90;&#x5206;&#x6563;&#x5230;&#x4E0D;&#x540C;&#x7684; CDN &#x670D;&#x52A1;&#x4E0A;&#x53BB;&#xFF0C;
&#x4F8B;&#x5982;&#x628A; JavaScript &#x6587;&#x4EF6;&#x653E;&#x5230; <code>js.cdn.com</code> &#x57DF;&#x540D;&#x4E0B;&#x3001;&#x628A; CSS &#x6587;&#x4EF6;&#x653E;&#x5230; <code>css.cdn.com</code> &#x57DF;&#x540D;&#x4E0B;&#x3001;&#x56FE;&#x7247;&#x6587;&#x4EF6;&#x653E;&#x5230; <code>img.cdn.com</code> &#x57DF;&#x540D;&#x4E0B;&#xFF0C;
&#x8FD9;&#x6837;&#x505A;&#x4E4B;&#x540E; <code>index.html</code> &#x9700;&#x8981;&#x53D8;&#x6210;&#x8FD9;&#x6837;&#xFF1A;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">&quot;UTF-8&quot;</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;stylesheet&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;//css.cdn.com/id/app_a6976b6d.css&quot;</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;app&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;//js.cdn.com/id/app_9d89c964.js&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<blockquote>
<p>&#x4F7F;&#x7528;&#x4E86;&#x591A;&#x4E2A;&#x57DF;&#x540D;&#x540E;&#x53C8;&#x4F1A;&#x5E26;&#x6765;&#x4E00;&#x4E2A;&#x65B0;&#x95EE;&#x9898;&#xFF1A;&#x589E;&#x52A0;&#x57DF;&#x540D;&#x89E3;&#x6790;&#x65F6;&#x95F4;&#x3002;&#x662F;&#x5426;&#x91C7;&#x7528;&#x591A;&#x57DF;&#x540D;&#x5206;&#x6563;&#x8D44;&#x6E90;&#x9700;&#x8981;&#x6839;&#x636E;&#x81EA;&#x5DF1;&#x7684;&#x9700;&#x6C42;&#x53BB;&#x8861;&#x91CF;&#x5F97;&#x5931;&#x3002;
&#x5F53;&#x7136;&#x4F60;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5728; HTML HEAD &#x6807;&#x7B7E;&#x4E2D; &#x52A0;&#x5165; <code>&lt;link rel=&quot;dns-prefetch&quot; href=&quot;//js.cdn.com&quot;&gt;</code> &#x53BB;&#x9884;&#x89E3;&#x6790;&#x57DF;&#x540D;&#xFF0C;&#x4EE5;&#x964D;&#x4F4E;&#x57DF;&#x540D;&#x89E3;&#x6790;&#x5E26;&#x6765;&#x7684;&#x5EF6;&#x8FDF;&#x3002;</p>
</blockquote>
<h2 id="&#x7528;-webpack-&#x5B9E;&#x73B0;-cdn-&#x7684;&#x63A5;&#x5165;">&#x7528; Webpack &#x5B9E;&#x73B0; CDN &#x7684;&#x63A5;&#x5165;</h2>
<p>&#x603B;&#x7ED3;&#x4E0A;&#x9762;&#x6240;&#x8BF4;&#x7684;&#xFF0C;&#x6784;&#x5EFA;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x4EE5;&#x4E0B;&#x51E0;&#x70B9;&#xFF1A;</p>
<ul>
<li>&#x9759;&#x6001;&#x8D44;&#x6E90;&#x7684;&#x5BFC;&#x5165; URL &#x9700;&#x8981;&#x53D8;&#x6210;&#x6307;&#x5411; CDN &#x670D;&#x52A1;&#x7684;&#x7EDD;&#x5BF9;&#x8DEF;&#x5F84;&#x7684; URL &#x800C;&#x4E0D;&#x662F;&#x76F8;&#x5BF9;&#x4E8E; HTML &#x6587;&#x4EF6;&#x7684; URL&#x3002;</li>
<li>&#x9759;&#x6001;&#x8D44;&#x6E90;&#x7684;&#x6587;&#x4EF6;&#x540D;&#x79F0;&#x9700;&#x8981;&#x5E26;&#x4E0A;&#x6709;&#x6587;&#x4EF6;&#x5185;&#x5BB9;&#x7B97;&#x51FA;&#x6765;&#x7684; Hash &#x503C;&#xFF0C;&#x4EE5;&#x9632;&#x6B62;&#x88AB;&#x7F13;&#x5B58;&#x3002;</li>
<li>&#x4E0D;&#x540C;&#x7C7B;&#x578B;&#x7684;&#x8D44;&#x6E90;&#x653E;&#x5230;&#x4E0D;&#x540C;&#x57DF;&#x540D;&#x7684; CDN &#x670D;&#x52A1;&#x4E0A;&#x53BB;&#xFF0C;&#x4EE5;&#x9632;&#x6B62;&#x8D44;&#x6E90;&#x7684;&#x5E76;&#x884C;&#x52A0;&#x8F7D;&#x88AB;&#x963B;&#x585E;&#x3002;</li>
</ul>
<p>&#x5148;&#x6765;&#x770B;&#x4E0B;&#x8981;&#x5B9E;&#x73B0;&#x4EE5;&#x4E0A;&#x8981;&#x6C42;&#x7684;&#x6700;&#x7EC8; Webpack &#x914D;&#x7F6E;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>);
<span class="hljs-keyword">const</span> ExtractTextPlugin = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;extract-text-webpack-plugin&apos;</span>);
<span class="hljs-keyword">const</span> {WebPlugin} = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;web-webpack-plugin&apos;</span>);

<span class="hljs-built_in">module</span>.exports = {
  <span class="hljs-comment">// &#x7701;&#x7565; entry &#x914D;&#x7F6E;...</span>
  output: {
    <span class="hljs-comment">// &#x7ED9;&#x8F93;&#x51FA;&#x7684; JavaScript &#x6587;&#x4EF6;&#x540D;&#x79F0;&#x52A0;&#x4E0A; Hash &#x503C;</span>
    filename: <span class="hljs-string">&apos;[name]_[chunkhash:8].js&apos;</span>,
    path: path.resolve(__dirname, <span class="hljs-string">&apos;./dist&apos;</span>),
    <span class="hljs-comment">// &#x6307;&#x5B9A;&#x5B58;&#x653E; JavaScript &#x6587;&#x4EF6;&#x7684; CDN &#x76EE;&#x5F55; URL</span>
    publicPath: <span class="hljs-string">&apos;//js.cdn.com/id/&apos;</span>,
  },
  <span class="hljs-built_in">module</span>: {
    rules: [
      {
        <span class="hljs-comment">// &#x589E;&#x52A0;&#x5BF9; CSS &#x6587;&#x4EF6;&#x7684;&#x652F;&#x6301;</span>
        test: <span class="hljs-regexp">/\.css$/</span>,
        <span class="hljs-comment">// &#x63D0;&#x53D6;&#x51FA; Chunk &#x4E2D;&#x7684; CSS &#x4EE3;&#x7801;&#x5230;&#x5355;&#x72EC;&#x7684;&#x6587;&#x4EF6;&#x4E2D;</span>
        use: ExtractTextPlugin.extract({
          <span class="hljs-comment">// &#x538B;&#x7F29; CSS &#x4EE3;&#x7801;</span>
          use: [<span class="hljs-string">&apos;css-loader?minimize&apos;</span>],
          <span class="hljs-comment">// &#x6307;&#x5B9A;&#x5B58;&#x653E; CSS &#x4E2D;&#x5BFC;&#x5165;&#x7684;&#x8D44;&#x6E90;&#xFF08;&#x4F8B;&#x5982;&#x56FE;&#x7247;&#xFF09;&#x7684; CDN &#x76EE;&#x5F55; URL</span>
          publicPath: <span class="hljs-string">&apos;//img.cdn.com/id/&apos;</span>
        }),
      },
      {
        <span class="hljs-comment">// &#x589E;&#x52A0;&#x5BF9; PNG &#x6587;&#x4EF6;&#x7684;&#x652F;&#x6301;</span>
        test: <span class="hljs-regexp">/\.png$/</span>,
        <span class="hljs-comment">// &#x7ED9;&#x8F93;&#x51FA;&#x7684; PNG &#x6587;&#x4EF6;&#x540D;&#x79F0;&#x52A0;&#x4E0A; Hash &#x503C;</span>
        use: [<span class="hljs-string">&apos;file-loader?name=[name]_[hash:8].[ext]&apos;</span>],
      },
      <span class="hljs-comment">// &#x7701;&#x7565;&#x5176;&#x5B83; Loader &#x914D;&#x7F6E;...</span>
    ]
  },
  plugins: [
    <span class="hljs-comment">// &#x4F7F;&#x7528; WebPlugin &#x81EA;&#x52A8;&#x751F;&#x6210; HTML</span>
    <span class="hljs-keyword">new</span> WebPlugin({
      <span class="hljs-comment">// HTML &#x6A21;&#x7248;&#x6587;&#x4EF6;&#x6240;&#x5728;&#x7684;&#x6587;&#x4EF6;&#x8DEF;&#x5F84;</span>
      template: <span class="hljs-string">&apos;./template.html&apos;</span>,
      <span class="hljs-comment">// &#x8F93;&#x51FA;&#x7684; HTML &#x7684;&#x6587;&#x4EF6;&#x540D;&#x79F0;</span>
      filename: <span class="hljs-string">&apos;index.html&apos;</span>,
      <span class="hljs-comment">// &#x6307;&#x5B9A;&#x5B58;&#x653E; CSS &#x6587;&#x4EF6;&#x7684; CDN &#x76EE;&#x5F55; URL</span>
      stylePublicPath: <span class="hljs-string">&apos;//css.cdn.com/id/&apos;</span>,
    }),
    <span class="hljs-keyword">new</span> ExtractTextPlugin({
      <span class="hljs-comment">// &#x7ED9;&#x8F93;&#x51FA;&#x7684; CSS &#x6587;&#x4EF6;&#x540D;&#x79F0;&#x52A0;&#x4E0A; Hash &#x503C;</span>
      filename: <span class="hljs-string">`[name]_[contenthash:8].css`</span>,
    }),
    <span class="hljs-comment">// &#x7701;&#x7565;&#x4EE3;&#x7801;&#x538B;&#x7F29;&#x63D2;&#x4EF6;&#x914D;&#x7F6E;...</span>
  ],
};
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x4EE3;&#x7801;&#x4E2D;&#x6700;&#x6838;&#x5FC3;&#x7684;&#x90E8;&#x5206;&#x662F;&#x901A;&#x8FC7; <code>publicPath</code> &#x53C2;&#x6570;&#x8BBE;&#x7F6E;&#x5B58;&#x653E;&#x9759;&#x6001;&#x8D44;&#x6E90;&#x7684; CDN &#x76EE;&#x5F55; URL&#xFF0C;
&#x4E3A;&#x4E86;&#x8BA9;&#x4E0D;&#x540C;&#x7C7B;&#x578B;&#x7684;&#x8D44;&#x6E90;&#x8F93;&#x51FA;&#x5230;&#x4E0D;&#x540C;&#x7684; CDN&#xFF0C;&#x9700;&#x8981;&#x5206;&#x522B;&#x5728;&#xFF1A;</p>
<ul>
<li><code>output.publicPath</code> &#x4E2D;&#x8BBE;&#x7F6E; JavaScript &#x7684;&#x5730;&#x5740;&#x3002;</li>
<li><code>css-loader.publicPath</code> &#x4E2D;&#x8BBE;&#x7F6E;&#x88AB; CSS &#x5BFC;&#x5165;&#x7684;&#x8D44;&#x6E90;&#x7684;&#x7684;&#x5730;&#x5740;&#x3002;</li>
<li><code>WebPlugin.stylePublicPath</code> &#x4E2D;&#x8BBE;&#x7F6E; CSS &#x6587;&#x4EF6;&#x7684;&#x5730;&#x5740;&#x3002;</li>
</ul>
<p>&#x8BBE;&#x7F6E;&#x597D; <code>publicPath</code> &#x540E;&#xFF0C;<code>WebPlugin</code> &#x5728;&#x751F;&#x6210; HTML &#x6587;&#x4EF6;&#x548C; <code>css-loader</code> &#x8F6C;&#x6362; CSS &#x4EE3;&#x7801;&#x65F6;&#xFF0C;&#x4F1A;&#x8003;&#x8651;&#x5230;&#x914D;&#x7F6E;&#x4E2D;&#x7684; <code>publicPath</code>&#xFF0C;&#x7528;&#x5BF9;&#x5E94;&#x7684;&#x7EBF;&#x4E0A;&#x5730;&#x5740;&#x66FF;&#x6362;&#x539F;&#x6765;&#x7684;&#x76F8;&#x5BF9;&#x5730;&#x5740;&#x3002;</p>
<blockquote>
<p>&#x672C;&#x5B9E;&#x4F8B;<a href="http://webpack.wuhaolin.cn/4-9CDN&#x52A0;&#x901F;.zip" target="_blank">&#x63D0;&#x4F9B;&#x9879;&#x76EE;&#x5B8C;&#x6574;&#x4EE3;&#x7801;</a></p>
</blockquote>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="4-8压缩代码.html" class="navigation navigation-prev " aria-label="Previous page: 4-8 压缩代码">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="4-10使用TreeShaking.html" class="navigation navigation-next " aria-label="Next page: 4-10 使用 Tree Shaking">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"4-9 CDN 加速","level":"1.6.9","depth":2,"next":{"title":"4-10 使用 Tree Shaking","level":"1.6.10","depth":2,"path":"4优化/4-10使用TreeShaking.md","ref":"4优化/4-10使用TreeShaking.md","articles":[]},"previous":{"title":"4-8 压缩代码","level":"1.6.8","depth":2,"path":"4优化/4-8压缩代码.md","ref":"4优化/4-8压缩代码.md","articles":[]},"dir":"ltr"},"config":{"plugins":["github-buttons","ga","modal","adsense"],"root":"./docs","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"search":{},"adsense":{"client":"ca-pub-9697944574373240","slot":"9319793387","format":"auto","element":".page-inner section","position":"top"},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"modal":{"closable":true,"excludeUrls":["\\?q=.+$","index.html","前言.html","\\/$","1-.+","2-2Output","3-1使用ES6语言","3-2使用TypeScript语言","3-4使用SCSS语言.html","3-5使用PostCSS.html","3-6使用React框架","3-7使用Vue框架","3-8使用Angular2框架","3-9为单页应用生成HTML","3-10管理多个单页应用","3-17通过Node.jsAPI启动Webpack","3-20加载SVG"],"html":"<div style='text-align: center'><a href='http://union-click.jd.com/jdc?d=1AMcaz'><img src='http://p0.meituan.net/scarlett/df16c51ffb95186df6f75d8c0e22b965842464.png' width='306px' height='411px'><a/> <h2><a target='_blank' href='http://union-click.jd.com/jdc?d=1AMcaz'>购买本书纸质版</a></h2></div>"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"github-buttons":{"buttons":[{"user":"gwuhaolin","type":"follow","size":"small","width":"150"},{"user":"gwuhaolin","repo":"dive-into-webpack","type":"star","size":"small"}]},"ga":{"configuration":"auto","token":"UA-54964850-3"},"sharing":{"facebook":false,"twitter":false,"google":false,"weibo":true,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"吴浩麟","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"isbn":"9787121331725","variables":{},"title":"深入浅出 Webpack","language":"zh-hans","gitbook":"*","description":"本书按照入门、配置、实战、优化、原理的路线层层深入，涵盖了 Webpack 的方方面面。对于小白，本书可以作为 Webpack 入门教程，对于老手，本书可以进一步加深你对 Webpack 的理解。"},"file":{"path":"4优化/4-9CDN加速.md","mtime":"2019-02-28T08:16:23.305Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-12-22T08:51:47.376Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-ga/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-modal/index.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-adsense/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

